package com.lm.paymentweb.controller;

import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.lm.paymentweb.common.Result;
import com.lm.paymentweb.remote.CommonRemote;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@RestController
public class CommonController {

    @Resource
    private CommonRemote commonRemote;

    /**
     * 上传文件至阿里云 oss
     *
     * @param file
     * @return Result
     */
    @PostMapping(value = "/common/uploadOSS",produces = {MediaType.APPLICATION_JSON_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result uploadOSS(@RequestParam(value = "file") MultipartFile file) {
        try {
            return commonRemote.uploadOSS(file,"blog-web");
        }catch (Exception e){
            e.printStackTrace();
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
    }

}
